<?php
/**
 * @name UserCommonController
 * @desc 控制器
 */
class UserCommonController extends ApiBaseController {

    public $user_info = [];

    public function init() {
        parent::init();
        $config = \Yaf\Application::app()->getConfig()->app;
        if($config['is_token_auth'] == 1){
            $r_token = $this->getRequest()->getServer('HTTP_X_AUTH_TOKEN');
//            $r_token = '56467071536C646B526C5A454D3035555A4570696246704F4E6C64736145746162573947574656586246426854577457656C4E584D55397154556447574531586545464B595730354E46527365464A4B545555786356465056454A4F595774574E5546616245307856455A776154417761584E58616B46704D444270';
            if(!$r_token || $r_token == 'null'){
                $this->ajaxReturn(403,"请先登录");
            }

            $tokenData = \Vendor\Kstring::getTokenStr($r_token);
            $tokenData = json_decode($tokenData, true);
            if(empty($tokenData) || !isset($tokenData['user_id']) || !isset($tokenData['ctime'])){
                $this->ajaxReturn(403, "登录失败");
            }
            if(time()-$tokenData['ctime']> 3600*24*30){
                $this->ajaxReturn(403, "登录已过期");
            }
//            $userModel = UserModel::getSingleton();
//            $this->user_info = $userModel->find(['user_id'=> $tokenData['user_id']]);
            $this->user_info = $tokenData;
        }
        if(empty($this->user_info)){
            $this->ajaxReturn(403,"请先登录");
        }
    }
}
